<template>
  <div>
    <el-container>

      <el-header style="height: 60px">
        <DealHeader :currency="currency" :key="currency"></DealHeader>
      </el-header>

      <el-container>
        <el-aside style="padding: 5px">
          <DealAside  @changeCurrency="onChangeCurrency"></DealAside>
        </el-aside>

        <el-container>
          <el-container>
            <el-main class="el-main-left">
              <DealMainLeft :currency="currency" :key="currency"/>
            </el-main>
            <el-main class="el-main-right">
              <DealMainRight :currency="currency" :key="currency"></DealMainRight>
            </el-main>
          </el-container>
          <el-footer style="height: 300px">
            <DealFooter :currency="currency" :key="currency"></DealFooter>
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import DealHeader from './coponents/DealHeader'
  import DealAside from './coponents/DealAside'
  import DealMainLeft from './coponents/DealMainLeft'
  import DealMainRight from './coponents/DealMainRight'
  import DealFooter from './coponents/DealFooter'

  export default {
    components: {DealHeader, DealAside, DealMainLeft, DealMainRight, DealFooter},
    data() {
      return {
        currency: "BTC-USDT",
        basePath: process.env.VUE_APP_WS_BASE_API,
        entrustTableData: [],
        nowTableData: []
      }
    },
    mounted() {
      // this.initWebSocket();
    },
    methods: {
      initWebSocket() {
        this.websock = new WebSocket("ws://localhost:8200/hourse/marketPublicSocket")
        this.websock.onerror = this.webSocketOnError
        this.websock.onmessage = this.webSocketOnMessage
      },
      webSocketOnError(e) {
        this.$notify({
          title: 'WebSocket连接发生错误',
          type: 'error',
          duration: 0
        })
      },
      webSocketOnMessage(e) {
        if (e != null) {
          var str_1 = e.data.split("_")[0];
          var str_2 = e.data.split("_")[1];
          var str_3 = e.data.split("_")[2];

          // 产品深度数据
          if (str_1 == 'ts') {
            if (str_2 == 'BTC-USDT') {
              var data = JSON.parse(str_3);
              this.entrustTableData = data.sell
              data.buy.forEach(item => {
                this.entrustTableData.push(item)
              })
            }
          }
        } else {
          this.$notify.error({
            title: '错误',
            message: '获取行情数据失败，请联系管理员'
          });
        }
      },
      webSocketSend(agentData) {
        this.websock.send(agentData)
      },
      onChangeCurrency(currency) {
        this.currency = currency
      }
    },


  }
</script>

<style lang="scss" scoped>
  .el-header {
    /*background-color: #B3C0D1;*/
    color: #333;
    text-align: center;
    /*line-height: 60px;*/
    padding-top: 5px;
    padding-bottom: 5px;
    border: 2px solid #d1dbe5;
  }

  .el-footer {
    /*background-color: #B3C0D1;*/
    color: #333;
    text-align: center;
    line-height: 60px;
    border: 2px solid #d1dbe5;
  }

  .el-aside {
    background-color: white;
    border: 2px solid #d1dbe5;
    color: #333;
    width: 200px;
    margin-bottom: 0px;
    height: 800px;
  }

  .el-main-left {
    /*background-color: #E9EEF3;*/
    border: 2px solid #d1dbe5;
    color: #333;
    width: 200px;
    margin-bottom: 0px
  }

  .el-main-right {
    /*background-color: #409EFF;*/
    border: 2px solid #d1dbe5;
    /*color: #333;*/
    text-align: center;
    /*line-height: 160px;*/
    width: 1000px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

</style>
